package io.jsen.meta.diff.context;


import io.jsen.meta.diff.obj.base.*;
import io.jsen.meta.diff.obj.ext.*;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

/**
 * @author jsen
 * @date 2021/4/6
 */
class DefaultMetaConvertInit {

    @SuppressWarnings("rawtypes")
    static void register() {
        MetaObjectConvertContext.register(Boolean.class,
                MetaBoolean::new);
        MetaObjectConvertContext.register(Byte.class,
                MetaByte::new);
        MetaObjectConvertContext.register(Character.class,
                MetaChar::new);
        MetaObjectConvertContext.register(Double.class,
                MetaDouble::new);
        MetaObjectConvertContext.register(Enum.class,
                MetaEnum::new);
        MetaObjectConvertContext.register(Float.class,
                MetaFloat::new);
        MetaObjectConvertContext.register(Integer.class,
                MetaInteger::new);
        MetaObjectConvertContext.register(Long.class,
                MetaLong::new);
        MetaObjectConvertContext.register(Short.class,
                MetaShort::new);
        MetaObjectConvertContext.register(String.class,
                MetaString::new);


        MetaObjectConvertContext.<MetaBoolean, Boolean>register(MetaBoolean.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaByte, Byte>register(MetaByte.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaChar, Character>register(MetaChar.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaDouble, Double>register(MetaDouble.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaEnum, Enum>register(MetaEnum.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaFloat, Float>register(MetaFloat.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaInteger, Integer>register(MetaInteger.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaLong, Long>register(MetaLong.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaShort, Short>register(MetaShort.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaString, String>register(MetaString.class,
                (field, s) -> s.getVal());


        // 扩展
        MetaObjectConvertContext.register(BigDecimal.class,
                MetaBigDecimal::new);
        MetaObjectConvertContext.register(BigInteger.class,
                MetaBigInteger::new);
        MetaObjectConvertContext.register(Date.class,
                MetaDate::new);
        MetaObjectConvertContext.register(LocalDate.class,
                MetaLocalDate::new);
        MetaObjectConvertContext.register(LocalTime.class,
                MetaLocalTime::new);
        MetaObjectConvertContext.register(LocalDateTime.class,
                MetaLocalDateTime::new);

        MetaObjectConvertContext.<MetaBigDecimal, BigDecimal>register(MetaBigDecimal.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaBigInteger, BigInteger>register(MetaBigInteger.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaDate, Date>register(MetaDate.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaLocalDate, LocalDate>register(MetaLocalDate.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaLocalTime, LocalTime>register(MetaLocalTime.class,
                (field, s) -> s.getVal());
        MetaObjectConvertContext.<MetaLocalDateTime, LocalDateTime>register(MetaLocalDateTime.class,
                (field, s) -> s.getVal());
    }

    private DefaultMetaConvertInit() {
    }
}
